package com.herench.bs.handler;

import com.herench.bs.agent.IPersonAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Created by wangwenkai on 2018/2/1.
 * 校验验证码
 */
@Component
@Handler(code = "100303",name="校验验证码")
public class VerificationCodeHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(final RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = null;
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String phone = requestMessage.getArgsPropertyStringValue("phone");
        String vcode = requestMessage.getArgsPropertyStringValue("vcode");
        Assert.isTrue(StringUtils.hasLength(channelCode), "sysCode 属性不能为空.");
        Assert.isTrue(StringUtils.hasLength(phone), "phone 属性不能为空.");
        Assert.isTrue(StringUtils.hasLength(vcode), "vcode 属性不能为空.");
        responseMessage = new ResponseMessage(requestMessage.getId());
        IPersonAgent agent = getCleverClinicContext().getApplicationContext().getBean(IPersonAgent.class);
        Map<String, Object> res = agent.verificationCodeHandler(channelCode,phone,vcode);
        getPropertiesFromInvokerResultMap(responseMessage, res);
        responseMessage.setData(res);
        return responseMessage;
    }
}
